from django.db import models
import uuid
import django.utils.timezone as timezone
from user.models import User


class Message(models.Model):
    ip = models.GenericIPAddressField(default='')
    content = models.CharField(max_length=1000, default='')
    time = models.DateTimeField(default=timezone.now)

    class Meta:
        db_table = 'message'

class Abracadabra(models.Model):
    name = models.CharField(max_length=100, default='')
    tag = models.CharField(max_length=1000, default='')
    negative_tag = models.CharField(max_length=300, default='')
    sample_image_url = models.CharField(max_length=100, default='')

    class Meta:
        db_table = 'abracadabra'


class Tag(models.Model):
    tag_name = models.CharField(max_length=1000, default='')
    ZN_translate = models.CharField(max_length=1000, default='')
    count = models.IntegerField(default=0)
    is_general = models.BooleanField(default=False)

    class Meta:
        db_table = 'tags'


class PictureTag(models.Model):
    picture = models.ForeignKey('Picture', on_delete=models.CASCADE)
    tag = models.ForeignKey('Tag', on_delete=models.CASCADE)

    class Meta:
        db_table = 'pic_tag'


class Picture(models.Model):
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    image_name = models.CharField(max_length=32)
    update_time = models.TimeField(auto_now_add=True)
    update_date_time = models.DateTimeField(default=timezone.localtime)
    create_time = models.BigIntegerField(default=0)
    tags = models.CharField(max_length=1024, default='')
    negative_tags = models.CharField(max_length=1024, default='')
    prefix = models.CharField(max_length=16, default='novelai')
    praise = models.IntegerField(default=0)
    is_show = models.BooleanField(default=True)
    is_chosen = models.BooleanField(default=False)
    is_delete = models.BooleanField(default=False)
    is_r18 = models.BooleanField(default=True)
    is_extract_tag = models.BooleanField(default=False)

    class Meta:
        db_table = 'pics'


class WaitedReviewPicture(models.Model):
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    image_name = models.CharField(max_length=32)
    tags = models.CharField(max_length=1024, default='')
    negative_tags = models.CharField(max_length=1024, default='')
    is_delete = models.BooleanField(default=False)
    is_review = models.BooleanField(default=False)

    class Meta:
        db_table = 'waited_review_pics'



class UseLog(models.Model):
    ip = models.GenericIPAddressField(default='')
    description = models.CharField(max_length=32, default='')
    data_time = models.DateTimeField(default=timezone.localtime)

    class Meta:
        abstract = True


class UseSearchTagLog(UseLog):
    tag = models.CharField(max_length=1024, default='')

    class Meta:
        db_table = 'search_tag_log'


class UseOrderLog(UseLog):
    order_mode = models.CharField(max_length=16, default='id')

    class Meta:
        db_table = "order_log"


class UsePictureLog(UseLog):
    target_id = models.ForeignKey(Picture, on_delete=models.CASCADE, default=1)

    class Meta:
        db_table = "picture_log"


class StarLog(models.Model):
    picture_id = models.ForeignKey(Picture, on_delete=models.CASCADE, default=1)
    user_id = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    star_date_time = models.DateTimeField(default=timezone.localtime)

    class Meta:
        db_table = "star_log"
